from utils.common import format_time_difference


# 爬取结果展示

class ScrapyResult:
    def __init__(self, scrapy_name=None, start_time=None):
        """
        初始化 ScrapyResult 对象

        :param scrapy_name: 爬虫名
        :param start_time: 爬虫开始时间
        """
        # 爬虫名
        self.scrapy_name = scrapy_name
        # 文件数量
        self.count = 0
        # 记录爬虫开始时间（时间戳）
        self.start_time = start_time
        # 记录爬虫结束时间，初始为 None（时间戳）
        self.end_time = None
        # 记录爬虫运行时间，初始为 None（时间戳）
        self.consume_time = None
        self.consume_time_str = None

    def set_consume_time_str(self, end_time):
        formatted_time = format_time_difference(self.start_time, end_time)
        self.consume_time_str = f"消耗总时长为: {formatted_time}"

    def get_result_info(self):
        return {
            'scrapy_name': self.scrapy_name,
            'count': self.count,
            'consume_time_str': self.consume_time_str,
        }


if __name__ == '__main__':
    pass
